package com.hua.controller;

import com.hua.common.Response;
import com.hua.common.ResponseCode;
import com.hua.domain.StoreInfo;
import com.hua.domain.domainVo.IncomeResponse;
import com.hua.exception.BusinessException;
import com.hua.service.StoreInfoService;
import com.hua.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chenlong
 * @version jdk1.8
 * @dscription ProjectOfMilk StoreInfoController 查询店铺的信息
 * @date 2022/10/19 13:52
 */

@Api(value = "与店铺有关的一些接口 可以查询店铺的信息 和上下架等")
@RestController
@RequestMapping("/storeInfo")
public class StoreInfoController {

    /**商铺数据service层*/
    @Resource
    private StoreInfoService storeInfoService;

    /**
     * 一个storeInfo 的接口
     * 根据店铺的id来查询店铺的信息
     */
    @ApiOperation(value = "根据店铺的主键id来查询店铺的信息 参数是商店的id")
    @GetMapping("/getStore")
    public Response<StoreInfo> storeInfo(@RequestParam Integer storeId) {
        //防止storeId  是空
        if (storeId == null) {
            throw new BusinessException(ResponseCode.SYSTEM_ERROR, "网络异常");
        }
        /*查询店铺的信息*/
        StoreInfo storeInfo = storeInfoService.getStoreInfo(storeId);
        return ResultUtils.success(storeInfo);
    }

    /**
     * 查询店铺的总收入 上个月的收入 去年的年收入 售卖出去的总数量
     */
    @ApiOperation(value = "查询店铺的总收入 上个月的收入 去年的年收入 售卖出去 参数是商店的id")
    @GetMapping("/getTotal")
    public Response<IncomeResponse> getTotal(@RequestParam Integer storeId) {
        //防止storeId  是空
        if (storeId == null) {
            throw new BusinessException(ResponseCode.SYSTEM_ERROR, "网络异常");
        }
        /*查询店铺的信息*/
        IncomeResponse incomeResponse = storeInfoService.getIncomeInfo(storeId);
        return ResultUtils.success(incomeResponse);
    }

    /**
     * 商店打烊 下架等接口
     */
    @ApiOperation(value = "商店打烊 下架等接口 参数是isBusiness是否下架 下架是1 0是上架 storeId是商店的id")
    @PutMapping("/storeOffOnline")
    public Response<Boolean> storeOffOnline(@RequestBody Integer isBusiness,@RequestBody Integer storeId) {
        //防止storeId  是空
        if (storeId == null) {
            throw new BusinessException(ResponseCode.SYSTEM_ERROR, "网络异常");
        }
        //商店打烊 下架
        Boolean storeDownRes = storeInfoService.storeOffOnline(isBusiness,storeId);
        return ResultUtils.success(storeDownRes);
    }

    /**
     * 商店打烊 下架等接口
     */
    @ApiOperation(value = "商店关门等接口 参数是isDelete是否下架 下架是1 0是上架 storeId是商店的id")
    @PutMapping("/storeDown")
    public Response<Boolean> storeDown(@RequestBody Integer isDelete,@RequestBody Integer storeId) {
        //防止storeId  是空
        if (storeId == null) {
            throw new BusinessException(ResponseCode.SYSTEM_ERROR, "网络异常");
        }
        //商店打烊 下架
        Boolean storeDownRes = storeInfoService.storeDown(isDelete,storeId);
        return ResultUtils.success(storeDownRes);
    }

    /**
     *更新商店的所有信息
     */
    @ApiOperation(value = "更新商店的信息 put请求")
    @PutMapping("/updateStoreInfo")
    public Response<Boolean> updateStoreInfo(@RequestBody StoreInfo storeInfo) {
        //防止storeId  是空
        if (storeInfo == null) {
            throw new BusinessException(ResponseCode.SYSTEM_ERROR, "更新店铺信息失败 请稍后再试");
        }
        //更新商店的所有信息
        Boolean updateStore = storeInfoService.updateStoreInfo(storeInfo);

        return ResultUtils.success(updateStore);
    }
}
